package com.retail.common.exception;

import com.retail.common.result.ResultCode;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 业务异常
 *
 * @author retail
 * @since 2024-01-01
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class BusinessException extends RuntimeException {

  private static final long serialVersionUID = 1L;

  /**
   * 错误码
   */
  private Integer code;

  /**
   * 错误消息
   */
  private String message;

  public BusinessException() {
    super();
  }

  public BusinessException(String message) {
    super(message);
    this.code = ResultCode.BUSINESS_ERROR.getCode();
    this.message = message;
  }

  public BusinessException(Integer code, String message) {
    super(message);
    this.code = code;
    this.message = message;
  }

  public BusinessException(ResultCode resultCode) {
    super(resultCode.getMessage());
    this.code = resultCode.getCode();
    this.message = resultCode.getMessage();
  }

  public BusinessException(ResultCode resultCode, String message) {
    super(message);
    this.code = resultCode.getCode();
    this.message = message;
  }

  public BusinessException(String message, Throwable cause) {
    super(message, cause);
    this.code = ResultCode.BUSINESS_ERROR.getCode();
    this.message = message;
  }

  public BusinessException(Integer code, String message, Throwable cause) {
    super(message, cause);
    this.code = code;
    this.message = message;
  }
}
